#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
# This template tests the API pickWeightedValue()
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU
from base.Sequence import Sequence


class MainSequence(Sequence):
    def generate(self, **kargs):
        reg_dict = {"0-14, 16-29": 50, "15, 30-31": 0}
        for i in range(10):
            reg_index = self.pickWeightedValue(reg_dict)
            if reg_index == 15 or reg_index == 30 or reg_index == 31:
                self.error("Failed to pick weighted value : %d" % reg_index)

            self.notice("Pick weighted value from register: %d" % reg_index)

        mem_dict = {"0x0-0x7fffffff": 0, "0x80000000-0xffffffff": 100}
        for i in range(10):
            mem_addr = self.pickWeightedValue(mem_dict)
            if mem_addr < 0x80000000:
                self.error("Failed to pick weighted value: 0x%x" % mem_addr)

            self.notice("Pick weighted value from memory : 0x%x" % mem_addr)


#  Points to the MainSequence defined in this file
MainSequenceClass = MainSequence

#  Using GenThreadGPGPU by default, can be overriden with extended classes
GenThreadClass = GenThreadGPGPU

#  Using EnvGPGPU by default, can be overriden with extended classes
EnvClass = EnvGPGPU
